package com.example.rabbitmq.test.controller;

import com.example.rabbitmq.test.processors.SystemMesageProcessor;
import com.example.rabbitmq.test.service.OrderService;
import com.example.rabbitmq.test.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
@RequestMapping("mq")
@EnableBinding({SystemMesageProcessor.class})
public class SendMessageController {

    @Autowired
    private OrderService orderService;

    @Autowired
    private ProductService productService;

    @Autowired
    SystemMesageProcessor systemMesageProcessor;

    @GetMapping("send")
    public String send(){
        productService.send();
        orderService.send();
        return "success";
    }
    @GetMapping("system/msg")
    public String systemMessage(){
        systemMesageProcessor.out().send(MessageBuilder.withPayload("系统消息:"+ System.currentTimeMillis()).build());
        return "success";
    }
}
